package com.leen.common.vo;



/**
 * 数据统一响应
 * @param <T>
 * @author wy
 */
public class ResultVO<T> {
    //响应编号
    private Integer code;
    //响应消息
    private String message;
    //携带的值
    private T data;

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }


    /**
     * 成功(新增，修改以及其它)
     * @return
     */
    public static  ResultVO success(){
        ResultVO<String>  vo=new ResultVO<String>();
        vo.setCode(ResultEnum.SUCDESS.getCode());
        vo.setMessage(ResultEnum.SUCDESS.getMessage());
        return vo;
    }

    /**
     * 2021/3/31日 新增一个成功的参数枚举
     * 成功(新增，修改以及其它)
     * @return
     */
    public static  ResultVO success(ResultEnum resultEnum){
        ResultVO<String>  vo=new ResultVO<String>();
        vo.setCode(resultEnum.getCode());
        vo.setMessage(resultEnum.getMessage());
        return vo;
    }
    /**
     * 成功(新增，修改以及其它)
     * @return
     */
    public static  ResultVO success(String message){
        ResultVO<String>  vo=new ResultVO<String>();
        vo.setCode(ResultEnum.SUCDESS.getCode());
        vo.setMessage(ResultEnum.SUCDESS.getMessage());
        vo.setData(message);
        return vo;
     }

    /**
     * 成功(传值)
     * @param data
     * @param <T>
     * @return
     */
     public static <T> ResultVO  success(T data){
         ResultVO  vo=new ResultVO();
         vo.setCode(ResultEnum.SUCDESS.getCode());
         vo.setMessage(ResultEnum.SUCDESS.getMessage());
         vo.setData(data);
         return vo;
     }


    /**
     * 失败，必须给原因
     * @param resultEnum
     * @return
     */
    public static  ResultVO failed( ResultEnum  resultEnum){
        ResultVO<String>  vo=new ResultVO<String>();
        vo.setCode(resultEnum.getCode());
        vo.setMessage(resultEnum.getMessage());
        return vo;
    }

    @Override
    public String toString() {
        return "ResultVO{" +
                "code=" + code +
                ", message='" + message + '\'' +
                ", data=" + data +
                '}';
    }
}
